package com.sky.service.impl;

import com.alibaba.fastjson.JSON;
import com.sky.context.BaseContext;
import com.sky.utils.HttpClientUtil;
import com.sky.vo.RankingResponse;
import com.sky.vo.RecommendResponse;
import org.springframework.stereotype.Service;

import java.util.HashMap;

@Service
public class RecommendServiceImpl {
    private static final String FLASK_API_BASE_URL = "http://localhost:5000/api/recommend";

    /**
     * 获取图书推荐数据
     * @param type
     * @return
     */
    public RecommendResponse getRecommendList(String type) {
        // 构建请求URL
        Integer id = BaseContext.getCurrentId();
        HashMap<String, String> map = new HashMap<>();
        map.put("type", type);
        map.put("id", String.valueOf(id));
        String json = HttpClientUtil.doGet(FLASK_API_BASE_URL,map);
        return JSON.parseObject(json, RecommendResponse.class);
    }
}
